{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Populating the interactive namespace from numpy and matplotlib\n"
     ]
    }
   ],
   "source": [
    "%pylab inline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "from util.dataset import read_data_set\n",
    "from util.image import half"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Prepare the data."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "from scipy.ndimage import convolve\n",
    "def nudge_dataset(X, Y):\n",
    "    direction_vectors = [\n",
    "        [[0, 1, 0],\n",
    "         [0, 0, 0],\n",
    "         [0, 0, 0]],\n",
    "\n",
    "        [[0, 0, 0],\n",
    "         [1, 0, 0],\n",
    "         [0, 0, 0]],\n",
    "\n",
    "        [[0, 0, 0],\n",
    "         [0, 0, 1],\n",
    "         [0, 0, 0]],\n",
    "\n",
    "        [[0, 0, 0],\n",
    "         [0, 0, 0],\n",
    "         [0, 1, 0]]]\n",
    "    \n",
    "    matrix_size = (int(sqrt(X.shape[1])),) * 2\n",
    "\n",
    "    shift = lambda x, w: convolve(x.reshape(matrix_size), mode='constant',\n",
    "                                  weights=w).ravel()\n",
    "    X = np.concatenate([X] +\n",
    "                       [np.apply_along_axis(shift, 1, X, vector)\n",
    "                        for vector in direction_vectors])\n",
    "    Y = np.concatenate([Y for _ in range(5)], axis=0)\n",
    "    return X, Y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "X_train, y_train = (asarray(d) for d in read_data_set('train', lambda d: half(half(d))))\n",
    "X_train, y_train = nudge_dataset(X_train, y_train)\n",
    "X_train = (X_train - np.min(X_train, 0)) / (np.max(X_train, 0) + 0.0001)  # 0-1 scaling"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "X_test, y_test = (asarray(d) for d in read_data_set('t10k', lambda d: half(half(d))))\n",
    "X_test, y_test = nudge_dataset(X_test, y_test)\n",
    "X_test = (X_test - np.min(X_test, 0)) / (np.max(X_test, 0) + 0.0001)  # 0-1 scaling"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Configuring Random Forest."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "from sklearn.ensemble import RandomForestClassifier"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "rf = RandomForestClassifier(n_estimators=100)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "RandomForestClassifier(bootstrap=True, class_weight=None, criterion='gini',\n",
       "            max_depth=None, max_features='auto', max_leaf_nodes=None,\n",
       "            min_samples_leaf=1, min_samples_split=2,\n",
       "            min_weight_fraction_leaf=0.0, n_estimators=100, n_jobs=1,\n",
       "            oob_score=False, random_state=None, verbose=0,\n",
       "            warm_start=False)"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "rf.fit(X_train, y_train)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Evaluation."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "from sklearn import metrics"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "RandomForestClassifier(bootstrap=True, class_weight=None, criterion='gini',\n",
      "            max_depth=None, max_features='auto', max_leaf_nodes=None,\n",
      "            min_samples_leaf=1, min_samples_split=2,\n",
      "            min_weight_fraction_leaf=0.0, n_estimators=100, n_jobs=1,\n",
      "            oob_score=False, random_state=None, verbose=0,\n",
      "            warm_start=False)\n",
      "             precision    recall  f1-score   support\n",
      "\n",
      "          0       0.97      0.99      0.98      4900\n",
      "          1       0.99      0.99      0.99      5675\n",
      "          2       0.94      0.97      0.96      5160\n",
      "          3       0.94      0.94      0.94      5050\n",
      "          4       0.96      0.94      0.95      4910\n",
      "          5       0.96      0.92      0.94      4460\n",
      "          6       0.97      0.98      0.97      4790\n",
      "          7       0.96      0.95      0.95      5140\n",
      "          8       0.93      0.94      0.94      4870\n",
      "          9       0.92      0.93      0.93      5045\n",
      "\n",
      "avg / total       0.95      0.95      0.95     50000\n",
      "\n"
     ]
    }
   ],
   "source": [
    "print('%s\\n%s' % (rf, metrics.classification_report(y_test, rf.predict(X_test))))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAPYAAAD7CAYAAABZjGkWAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJztnV/MZ0lZ57/99nTTQ9P0IKyCzpDhQoka40iUbAZ0WP8F\nXdQbE2NiNJp4pS5ZI0G9MOuV2Stcd7PJ+gcjq8EL/xtNUDYKKBFFGP8BxjESenRoDMMM9DQzMPO+\ne3Heeql+5vlb9dQ55327vsnJqfM8T9WpU6c+p+qc8/sDTE1NTU1NTU1NTU1NTU1NTU1NTU1NTU1N\nTU2dWp1LKOMooYypqakGHRwc4PDw8Fkc37FFZajOnTvnWkdivXmefPJJXL58GQcHBzh37hwODg5u\nWajNExOJfeihh/Dyl7/8xH7u3LmTpd7m0pbfk373u9+N+++/HwBwdHR0sq7To2wA8L73vQ/33Xcf\nDg8PT+KOjo5u2d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yM8VHAN4O4L0AfnDF/dZ/xPE+AL+Az82eUrQl2Nt+lnQ/eh6We63XYxm519QhltuB\nuwF8HdZ7H/o6AB/Dcm+75Wj9KiwX1G8B8ENYRtE1VP6I438fr58A83v9PdoS7H/F8gCp6B4so/bt\npAsAfhPArwL4nQ3r8TiAPwDw1Svt734A347lHvetAL4ewFtW2netR47X/w7gt7HcHq4h7o84XrHS\nvofrDiy/U34vlnu8tR+e4XjfWz08O4elM79po/2/CMuTWQC4E8A7AXzDBvV4ANs8FX8ugCvH6csA\n/hzAN6+4/3fic3/E8d8A/PcV9z1c34LlafBDAH5i5X2/FcC/AXgKy73+2n+E8GosU+EHsUxJ34/l\n9d9a+gos93cPYnnl84YV913rAWzzVPxlWI79QSyvG9fuf1+JZcT+GwC/heSn4lNTU1NTU1NTU1NT\nU1NTU1NTU1NTU1NTU1NTU1NTU1NTU1ND9f8BkLFbo0gh12cAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7ff030096f28>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "imshow(rf.feature_importances_.reshape((7, 7)), cmap='gray');"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.4.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
